package com.bong.ring.activity.config;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.GridLayout;

import com.bong.ring.R;
import com.bong.ring.util.Common;

public class WatchConfigActivity extends AppCompatActivity {

    int defaultId=0;
    View present;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_watch_config);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("表盘");
        GridLayout layout = findViewById(R.id.layout1);
        int id=0;
        for (int i = 0; i < layout.getChildCount(); i++) {
            View v = layout.getChildAt(i);
            if(id==defaultId)
                present=v;
            v.setId(id++);
            v.setOnClickListener(picClickListener);
        }
        layout = findViewById(R.id.layout2);
        for (int i = 0; i < layout.getChildCount(); i++) {
            View v = layout.getChildAt(i);
            if(id==defaultId)
                present=v;
            v.setId(id++);
            v.setOnClickListener(picClickListener);
        }
    }

    View.OnClickListener picClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(defaultId!=v.getId())
            {
                present.setBackgroundResource(0);
                present=v;
                v.setBackgroundResource(R.drawable.pic_back);
                defaultId=v.getId();
            }
            Common.showToast(WatchConfigActivity.this,""+v.getId());
        }
    };

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}
